<script language=javascript>
function new_cat()
{
	if (document.getElementById('new').selected == true)
		document.getElementById('i_new').style.display = "block";
	else
		document.getElementById('i_new').style.display = "none";
	//	if (document.getlementbyid('new').style.display == none)
	//	document.getelementbyid('new').style.display == block;
}

</script>

<?php
require_once("pages/functions.php");

get_link();

if (isset($_POST['prod_name']) AND isset($_POST['prod_price']) 
		AND isset($_POST['prod_tva']) AND isset($_POST['prod_cel'])
			AND isset($_POST['prod_max']) AND isset($_POST['prod_code'])
				AND isset($_POST['prod_cat']) AND isset($_POST['prod_four_price'])
					AND isset($_POST['prod_tva_four']) AND isset($_POST['prod_four_name']))
{
	
if (isset($_POST['prod_name']) AND isset($_POST['prod_price']) 
		AND isset($_POST['prod_tva']) AND isset($_POST['prod_cel'])
			AND isset($_POST['prod_max']) AND isset($_POST['prod_code'])
				AND isset($_POST['prod_cat']) AND isset($_POST['prod_four_price'])
					AND isset($_POST['prod_tva_four']) AND isset($_POST['prod_four_name']))
		{
		if (is_numeric($_POST['prod_price']) AND is_numeric($_POST['prod_tva'])
				AND is_numeric($_POST['prod_max']) AND is_numeric($_POST['prod_code'])
				  AND is_numeric($_POST['prod_tva_four']) AND is_numeric($_POST['prod_cel']) AND is_numeric($_POST['prod_four_price']))
			{
				global $connect;
				$query = "call insert_produit('".$_POST['prod_name']."','".$_POST['prod_code']."','".$_POST['prod_cat']."', '".$_GET['idmag']."', '".$_POST['prod_price']."' , '".$_POST['prod_tva']."' , '".$_POST['prod_cel']."' , '".$_POST['prod_four_name']."', '".$_POST['prod_four_price']."' , '".$_POST['prod_tva_four']."' , '".$_POST['prod_quant']."' ,'".$_POST['prod_max']."');";
				 mysql_query($query, $connect)or die (mysql_error());
				echo "<div class='box_success'>Nouveau produit ajout&eacute; </div><br />";
			}
			else
				echo "<p class='box_error'>Attention certains champs ne prennent que des chiffres</p> <br />";
			
		}
		else
			echo "<p class='box_error'>Certains champs n'ont pas &eacute;t&eacute; remplis </p> <br />";
}
?>
<div id="ventes">
	<div id="prd_list">	
		<center>
		<h1>Ajout d'un nouveau produit </h1><br />
			<?php echo "<form action='index.php?page=produits&action=add&idmag=".$_GET['idmag']."' method='post'>"; ?>
				<table  border="0" cellspacing="8" cellpadding="40" width="400px">
				<tr > <td>Nom :</td><td><input type="text" name="prod_name" /></td> </tr>
				<tr> <td>Categorie:</td>
				<?php
			global $connect;
			$query = "SELECT * FROM categories";
			$mag_list = mysql_query($query, $connect) or die(mysql_error());	
			echo "<td>";
			echo "<select onChange='new_cat();' name='prod_cat'>";
			echo "<option> </option>";
			while ($data = mysql_fetch_array($mag_list))
			{
				echo "<option id='".$data['NCATEGORIE']."' value=".$data['NOMCATEGORIE']." >".$data['NOMCATEGORIE']."</option>";
			}
			echo '<option id="new" >----nouvelle categorie----</option>';
			echo "</select>";
			echo "<input class='NewCat' style='display:none'id='i_new' type='text' value='Nouvelle categorie'/>";
			echo "</td> </tr>";
			?>
				<tr> <td>Prix :</td><td><input type="text" name="prod_price" /></td> </tr>
				<tr> <td>TVA produit :</td><td><input type="text" name="prod_tva" /></td> </tr>
				<tr> <td>Cellule :</td><td><input type="text" name="prod_cel" /></td> </tr>
				<tr> <td>Quantit&eacute;</td><td><input type="text" name="prod_quant" /></td> </tr>
				<tr> <td>Quantit&eacute; max:</td><td><input type="text" name="prod_max" /></td> </tr>
				<tr> <td>Code produit:</td> <td><input type="text" name="prod_code" /></td> </tr>
				<tr> <td>Nom fournisseur:</td> 
				<?php
				$query = "SELECT * FROM fournisseurs";
				$four_list = mysql_query($query, $connect) or die (mysql_error());
				echo "<td>";
				echo "<select style='width:150px' name='prod_four_name'>";
				while ($data = mysql_fetch_array($four_list))
				{
					echo "<option id='".$data['NFOURNISSEUR']."' value=".$data['NOM'].">".$data['NOM']."</option>";
				}
				echo "</select>";
				echo "</td>";
				?>
				<tr> <td>Prix fournisseur:</td> <td><input type="text" name="prod_four_price" /></td> </tr>
				<tr> <td>TVA fournisseur:</td> <td><input type="text" name="prod_tva_four" /></td> </tr>
				<tr><td><input type="submit" value="Ajouter"></td></tr>
			</table>
			<br />
			</form>
		</center>
	</div>
	<?php echo "<h1><center><a href='index.php?page=magasins&show_mag_id=".$_GET['idmag']."'><img src='img/jamembo-back.png' width='30px' height='30px'/> Retour a la liste des produits du magasin</a></center></h1>"; ?>
</div>


